package com.czm.art_light.service.impl;

import com.czm.art_light.annotation.CacheWithLock;
import com.czm.art_light.constant.CommonConsts;
import com.czm.art_light.entity.ArtFeedbackType;
import com.czm.art_light.mapper.ArtFeedbackTypeMapper;
import com.czm.art_light.param.response.ArtFeedbackTypeRespDto;
import com.czm.art_light.service.ArtFeedbackTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 反馈类型信息 服务类
 */
@Service
public class ArtFeedbackTypeServiceImpl implements ArtFeedbackTypeService {
    @Autowired
    private ArtFeedbackTypeMapper artFeedbackTypeMapper;

    /**
     * 返回所有的反馈类型内容
     */
    @CacheWithLock(
            cacheName = "allFeedbackTypes",
            key = "",   //从参数对象提取属性
            expireTime = CommonConsts.FEEDBACK_TYPE_CACHE_EXPIRATION_TIME,
            cacheNull = true,
            enabled = true
    )
    @Override
    public List<ArtFeedbackTypeRespDto> getAllFeedbackTypes() {
        List<ArtFeedbackType> allFeedbackTypeContent = artFeedbackTypeMapper.getAllFeedbackTypeContent();
        if (allFeedbackTypeContent.isEmpty()) {
            return new ArrayList<>();
        }
        ArrayList<ArtFeedbackTypeRespDto> artFeedbackTypeRespDtos = new ArrayList<>();
        for (ArtFeedbackType artFeedbackType : allFeedbackTypeContent) {
            artFeedbackTypeRespDtos.add(ArtFeedbackTypeRespDto.builder()
                    //反馈类型唯一标识
                    .id(artFeedbackType.getId())
                    //反馈类型名称
                    .typeName(artFeedbackType.getTypeName())
                    .build());
        }
        return artFeedbackTypeRespDtos;
    }
}
